<template>
  <pageTabelLayout>
    <template #pageHeader>
      <div class="my-tool-bar">
        <Toolbar class="gesture" :items="pageData.btnList" @add="addHandler" @del="deleteHandler"
                 @select="selectHandler">
        </Toolbar>
      </div>
    </template>
    <template #pageTabel>
      <a-spin :loading="pageData.pageLoading" tip="加载中" dot style="height: 100%; width: 100%; z-index: 999">
          <div style="width: 100%; height: 100%">
            <encapsulation-agrid ref="table1Ref" :configaggrid="configTable1"></encapsulation-agrid>
          </div>
      </a-spin>
    </template>
    <a-drawer style="z-index: 999" ok-text="保存" cancel-text="关闭" :drawer-style="{ zIndex: 9999 }"
              :mask-closable="false"
              :width="400" :ok-loading="pageData.pageLoading" :visible="pageData.showAdd" unmountOnClose @ok="sideOk"
              @cancel="pageData.showAdd = false">
      <template #title>
        {{ pageData.sideTitle }}
      </template>
      <div>
        <a-form ref="formRef" layout="horizontal" :model="isbiaodan">
          <a-form-item label-col-flex="120px" label="坯布编号" field="pibubianhao"
                       :validate-trigger="['change', 'blur']"
                       :rules="[{ required: true, message: '坯布编号必填' }]">
            <a-select popup-container="html" @input-value-change="sousuopibubianhao" :disabled="jinyong2"
                      :loading="loading" class="bacClass"
                      v-model="isbiaodan.pibubianhao" :filter-option="false" allow-search allow-clear
                      @focus="guangzhu('坯布编号')"
                      @change="ispibu">
              <a-option v-for="item in isbiaodan.pibubianhaolist" @click="huoquzhi2(item)" :value="item.greyCode"
                        :key="item.greyCode">{{ item.greyCode + ' —— ' + item.grayFabricName }}
              </a-option>
            </a-select>
          </a-form-item>
          <a-form-item label-col-flex="120px" label="坯布名称" field="pibumingcheng"
                       :validate-trigger="['change', 'blur']"
                       :rules="[{ required: true, message: '坯布名称必填' }]">
            <a-input disabled placeholder="" v-model="isbiaodan.pibumingcheng"/>
          </a-form-item>
          <a-form-item label-col-flex="120px" label="外加工坯布编号" field="waijiagongpibubianhao"
                       :validate-trigger="['change', 'blur']"
                       :rules="[{ required: true, message: '外加工坯布编号必填' }]">
            <a-input @input="guangzhu('坯布编号')" :disabled="jinyong2" class="bacClass" placeholder=""
                     v-model="isbiaodan.waijiagongpibubianhao"/>
          </a-form-item>
          <a-form-item label-col-flex="120px" label="外加工坯布名称" field="waijiagongpibumingcheng"
                       :validate-trigger="['change', 'blur']"
                       :rules="[{ required: true, message: '外加工坯布名称必填' }]">
            <a-input @input="guangzhu('坯布名称')" :disabled="jinyong2" class="bacClass" placeholder=""
                     v-model="isbiaodan.waijiagongpibumingcheng"/>
          </a-form-item>
          <a-form-item label-col-flex="120px" label="外加工工厂" field="waijiagongchang"
                       :validate-trigger="['change', 'blur']"
                       :rules="[{ required: true, message: '外加工工厂必填' }]">
            <a-cascader @focus="huoquzhi3" v-model="isbiaodan.waijiagongchang" :options="isbiaodan.waijiagongchanglist"
                        allow-clear ref="casOb" class="bacClass" :title="isbiaodan.title" @change="cascaderChange"
                        popup-container="html"/>
          </a-form-item>
          <a-form-item label-col-flex="120px" label="客户" field="customName"
                       :rules="[{ required: true, message: '客户名称必填' }]" :validate-trigger="['change', 'blur']">
            <a-select popup-container="html" class="bacClass" :loading="loading" placeholder="" @search="handleSearch1"
                      v-model="isbiaodan.customName" :filter-option="false" allow-search allow-clear @focus="focusSel1">
              <a-option v-for="item in pageData.customNameList" :value="item['brandName']" :key="item['brandName']">{{
                  item['brandName']
                }}
              </a-option>
            </a-select>
          </a-form-item>
          <a-form-item label-col-flex="120px" label="备注" field="remark">
            <!-- <a-input v-model="dataForm.remark" /> -->
            <a-textarea class="bacClass" placeholder="" v-model="isbiaodan.remark" :max-length="400" allow-clear
                        show-word-limit/>
          </a-form-item>
        </a-form>
      </div>
    </a-drawer>
  </pageTabelLayout>
</template>

<script lang="ts">
import {post} from '@/api/http'
import {useTable, useRowKey, useTableColumn, usePagination, useRowSelection} from '@/hooks/table'
import emitter from '@/hooks/useEventBus'
import {ref, reactive, onMounted, toRefs} from 'vue'
import Toolbar from '@/components/Toolbar.vue'
import {Button, Form, Message, Modal} from '@arco-design/web-vue'
import {FormInstance} from '@arco-design/web-vue/es/form'
import {baseURL} from '../../../api/axios.config'
import axios from 'axios'
import filedownload from 'js-file-download'
import usePermission from '@/store/modules/permission'
import PageTabelLayout from '@/components/pageTabelLayout.vue'
import MyTable from '@/components/MyTable'
import ButtonRenderer from '@/components/TableCellRenderer/ButtonRenderer'
import {template} from 'lodash'
import {setupGlobalComponent} from '@/layouts'
import {pagingList} from '@/api/paging'
import {slicing} from '@/utils/caseFrimAndSecRig'
// 引入

import {localeText} from '@/api/aggridZw'
import {saveOrUpdateGridState as saveOrUpdateGridState01} from '@/hooks/useGridState'

interface BrandInfo {
  id: any
  brandCode: string
  brandName: string
  clothClass: string
  remark: string
  deleteState: number | string
  createName: string
  createTime: string
  updateName: string
  updateTime: string
  customName: any
}

export default {
  name: 'ExternalprocessRawmaterials',

  setup() {
    const table1Ref = ref<any>(null)
    const tableColumns = [
      {
        title: '序号',
        key: 'serialNumber',
        dataIndex: 'serialNumber',
        width: 150,
      },
      {
        title: '坯布编号',
        key: 'greigeCode',
        dataIndex: 'greigeCode',
        width: 150,
      },

      {
        title: '坯布名称',
        key: 'greigeName',
        dataIndex: 'greigeName',
        width: 150,
      },
      {
        title: '外加工坯布编号',
        key: 'outsideGreigeCode',
        dataIndex: 'outsideGreigeCode',
        width: 150,
      },

      {
        title: '外加工坯布名称',
        key: 'outsideGreigeName',
        dataIndex: 'outsideGreigeName',
        width: 150,
      },
      {
        title: '外加工工厂',
        key: 'outsideFirm',
        dataIndex: 'outsideFirm',
        width: 150,
      },
      {
        title: '客户',
        key: 'customName',
        dataIndex: 'customName',
        width: 150,
      },
      {
        title: '备注',
        key: 'remark',
        dataIndex: 'remark',
        width: 150,
      },
      {
        title: '创建人',
        key: 'createName',
        dataIndex: 'createName',
        width: 150,
      },
      {
        title: '创建时间',
        key: 'createTime',
        dataIndex: 'createTime',
        width: 200,
      },
      {
        title: '最后修改人',
        key: 'updateName',
        dataIndex: 'updateName',
        width: 150,
      },
      {
        title: '最后修改时间',
        key: 'updateTime',
        dataIndex: 'updateTime',
        width: 200,
      },
      // {
      //     title: "删除状态",
      //     key: "deleteState",
      //     dataIndex: "deleteState",
      //     width: 100,
      //     slotName: "deleteState",
      //     fixed: 'right'
      // },
      {
        title: '操作',
        key: 'id',
        slotName: 'act',
        width: 150,
        fixed: 'right',
      },
    ]
    let tc: any[] = tableColumns.map((o) => {
      let obj = {
        headerName: o.title,
        field: o.key,
        pinned: o['fixed'],
        width: 250,
        tooltipField: o.key,
      }
      if (o.slotName === 'act') {
        obj['resizable'] = false
        obj['filter'] = false
        obj['sortable'] = false
        obj['lockPosition'] = 'right'
        obj['width'] = 90
        obj['cellRenderer'] = {
          template: `
            <a-tag class="tagCss" v-if="e" @click="a">修改</a-tag>`,
          setup(props: any) {
            const a = () => {
              editHandler(props.params.data)
            }
            return {
              e: pageData.isEdit,
              a,
            }
          },
        }
      }

      return obj
    })
    tc.unshift({
      showRowGroup: 'hide_def',
      headerName: "",
      "checkboxSelection": true,
      "headerCheckboxSelection": true,
      "pinned": "left",
      "width": 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: "left",
    })

    let configTable1 = {
      url: 'product/Contrast/getPage', //接口路径
      queryData: {
        //接口参数
        deleteState: 0,
      },
      paginationShow: true, //分页是否显示
      invokeiIterface: true, //是否调用接
      rowMultiSelectWithClick: true, //点击行是否多选
      column: tc,
      fileName: 'ExternalprocessRawmaterials-1'
    }

    const total = ref(0)
    const page = ref(1)
    const size = ref(10)

    function PageSize(val: any) {
      page.value = val
      doRefresh()
    }

    function change1(val: any) {
      size.value = val
      doRefresh()
    }

    const headerShow = ref<boolean>(true)

    function doRefresh() {
      table1Ref.value.setQuery({
        deleteState: 0,
      })
    }

    const {selectedRowKeys, onSelectionChange} = useRowSelection()
    const pagination = usePagination(doRefresh)
    const table = useTable()
    const rowKey = useRowKey('id')
    const pageData = reactive<{
      showAdd: boolean
      sideTitle: string
      dropDownData: any
      nameList: []
      pageLoading: boolean
      typeList: []
      dropDownData1: any
      rHeight: any
      btnList: any[]
      isEdit: boolean
      customNameList: any[]
    }>({
      nameList: [],
      showAdd: false,
      sideTitle: '新增坯布编号对照',
      dropDownData: '',
      pageLoading: false,
      typeList: [],
      dropDownData1: '',
      rHeight: 0,
      btnList: [],
      isEdit: false,
      customNameList: [],
    })

    interface gcType {
      id: any
      company: any
    }

    //下拉框得到焦点
    const focusSel = () => {
      selCxAll({brandName: '', deleteState: 0})
    }
    //下拉数据
    const options = ref<any>(pageData.nameList)
    const loading = ref(false)
    const handleSearch = (value: any) => {
      if (value) {
        const ob = {brandName: value, deleteState: 0}
        loading.value = true
        selCxAll(ob)
        options.value = pageData.nameList
        loading.value = false
      } else {
        options.value = []
      }
    }

    //下拉框查询
    function selCxAll(val: any) {
      post({
        url: 'product/Brand/getFieldValue',
        data: val,
      }).then(({data, code}: any) => {
        if (code === 200) {
          let dataList: any = []
          data.forEach(function (o: any) {
            dataList.push(o['brandName'])
          })
          pageData.nameList = dataList
        } else {
          Message.error({
            content: '查询失败！',
            duration: 5000,
          })
        }
      })
    }

    onMounted(() => {
      // 切换tap到本页面执行的方法
      emitter.on('ExternalprocessRawmaterials', () => {
        // selCxAll1({});
        doRefresh()
      })
    })
    let cxbl = ''
    //查询
    const selectHandler = () => {
      page.value = 1
      cxbl = pageData.dropDownData
      doRefresh()
    }
    const queryData = reactive({
      clothType: '',
    })
    const addHandler = () => {
      jinyong1.value = false
      jinyong2.value = false
      isbiaodan.value.yuanliaobianhao = ''
      isbiaodan.value.yuanliaomingcheng = ''
      isbiaodan.value.waijiagongyuanbianhao = ''

      isbiaodan.value.waijiagongyuanliaomingcheng = ''
      isbiaodan.value.pibubianhao = ''
      isbiaodan.value.pibumingcheng = ''
      isbiaodan.value.waijiagongpibubianhao = ''
      isbiaodan.value.waijiagongpibumingcheng = ''
      isbiaodan.value.waijiagongchang = null
      isbiaodan.value.remark = ''
      isbiaodan.value.customName = ''
      isbiaodan.value.title = ''
      pageData.showAdd = true
      pageData.sideTitle = '新增坯布编号对照'
    }
    const dataForm = reactive<BrandInfo>({
      id: null,
      remark: '',
      brandName: '',
      clothClass: '',
      deleteState: '',
      createName: '',
      createTime: '',
      updateName: '',
      updateTime: '',
      brandCode: '',
      customName: null,
    })

    // 表格准备事件
    const gridOption = ref()
    const colState = ref()
    let gridOptions = ref()
    const gridReady = (params: any) => {
      gridOptions.value = params
      gridOption.value = params.api
      colState.value = params.columnApi
    }

    let formRef = ref<FormInstance>()
    const sideOk = () => {
      formRef.value?.validate().then((err) => {
        if (!err) {
          formRef.value?.validate().then((err) => {
            if (!err) {
              pageData.pageLoading = true
              if (pageData.sideTitle === '新增坯布编号对照') {
                post({
                  url: '/product/Contrast/insert',
                  data: [
                    {
                      rawmaterialCode: isbiaodan.value.yuanliaobianhao,
                      materialsName: isbiaodan.value.yuanliaomingcheng,
                      outsideCode: isbiaodan.value.waijiagongyuanbianhao,
                      outsideName: isbiaodan.value.waijiagongyuanliaomingcheng,
                      greigeCode: isbiaodan.value.pibubianhao,
                      greigeName: isbiaodan.value.pibumingcheng,
                      outsideGreigeCode: isbiaodan.value.waijiagongpibubianhao,
                      outsideGreigeName: isbiaodan.value.waijiagongpibumingcheng,
                      remark: isbiaodan.value.remark,
                      customName: isbiaodan.value.customName,
                      outsideFirmId: isbiaodan.value.waijiagongchang,
                      outsideFirm: isbiaodan.value.title,
                    },
                  ],
                })
                    .then((res: any) => {
                      if (res.code === 200) {
                        formRef.value?.resetFields()
                        pageData.showAdd = false

                        Message.success({
                          content: '新增成功',
                          duration: 5000,
                        })
                      } else {
                        Message.error({
                          content: res.message,
                          duration: 5000,
                        })
                      }
                      doRefresh()
                    })
                    .finally(() => {
                      doRefresh()
                      pageData.pageLoading = false
                    })
              } else {
                post({
                  url: '/product/Contrast/update',
                  data: [
                    {
                      id: id.value,
                      rawmaterialCode: isbiaodan.value.yuanliaobianhao,
                      materialsName: isbiaodan.value.yuanliaomingcheng,
                      outsideCode: isbiaodan.value.waijiagongyuanbianhao,
                      outsideName: isbiaodan.value.waijiagongyuanliaomingcheng,
                      greigeCode: isbiaodan.value.pibubianhao,
                      greigeName: isbiaodan.value.pibumingcheng,
                      outsideGreigeCode: isbiaodan.value.waijiagongpibubianhao,
                      outsideGreigeName: isbiaodan.value.waijiagongpibumingcheng,
                      outsideFirmId: isbiaodan.value.waijiagongchang,
                      remark: isbiaodan.value.remark,
                      customName: isbiaodan.value.customName,
                      outsideFirm: isbiaodan.value.title,
                    },
                  ],
                })
                    .then((res: any) => {
                      if (res.code === 200) {
                        formRef.value?.resetFields()
                        pageData.showAdd = false
                        Message.success({
                          content: '修改成功',
                          duration: 5000,
                        })
                      } else {
                        Message.error({
                          content: res.message,
                          duration: 5000,
                        })
                      }
                    })
                    .finally(() => {
                      doRefresh()
                      pageData.pageLoading = false
                    })
              }
            }
          })
        }
      })
    }
    const deleteHandler = () => {
      if (table1Ref.value.getSelectedRows().length === 0) {
        Message.error('请先勾选')
        return
      }

      Modal.confirm({
        title: '系统提示',
        content: '确认删除选中的数据?',
        onOk() {
          pageData.pageLoading = true
          post({
            url: '/product/Contrast/delete',
            data: table1Ref.value.getSelectedRows().map((o: any) => {
              return o.id
            }),
          })
              .then(({code, data}: any) => {
                if (code === 200) {
                  Message.success({
                    content: '删除成功',
                    duration: 5000,
                  })
                  pagination.page = 1
                  doRefresh()
                } else {
                  Message.error({
                    content: '删除失败',
                    duration: 5000,
                  })
                }
              })
              .finally(() => {
                pageData.pageLoading = false
              })
        },
      })
    }

    let curobj = null
    const editHandler = (record: any) => {
      id.value = record.id
      isbiaodan.value.yuanliaobianhao = record.rawmaterialCode
      isbiaodan.value.yuanliaomingcheng = record.materialsName
      isbiaodan.value.waijiagongyuanbianhao = record.outsideCode

      isbiaodan.value.waijiagongyuanliaomingcheng = record.outsideName
      isbiaodan.value.pibubianhao = record.greigeCode
      isbiaodan.value.pibumingcheng = record.greigeName
      isbiaodan.value.waijiagongpibubianhao = record.outsideGreigeCode
      isbiaodan.value.waijiagongpibumingcheng = record.outsideGreigeName
      isbiaodan.value.waijiagongchang = record.outsideFirmId
      isbiaodan.value.remark = record.remark
      isbiaodan.value.customName = record.customName
      isbiaodan.value.title = record.outsideFirm

      if (
          isbiaodan.value.yuanliaobianhao != '' ||
          isbiaodan.value.waijiagongyuanbianhao != '' ||
          isbiaodan.value.waijiagongyuanliaomingcheng != ''
      ) {
        jinyong2.value = true
      } else {
        jinyong2.value = false
      }
      if (
          isbiaodan.value.pibubianhao != '' ||
          isbiaodan.value.waijiagongpibubianhao != '' ||
          isbiaodan.value.waijiagongpibumingcheng != ''
      ) {
        jinyong1.value = true
      } else {
        jinyong1.value = false
      }
      pageData.sideTitle = '修改坯布编号对照'
      pageData.showAdd = true
    }
    //判断是否填写了中文
    const isChiese = (value: string, cb: Function) => {
      return new Promise<void>((resolve) => {
        if (window.encodeURI(value).indexOf('%') !== -1) {
          cb('填写的值不能包含中文！')
        }
        resolve()
      })
    }
    //input离开焦点 将小写转大写
    const inputBlur = () => {
      dataForm.brandCode = dataForm.brandCode.toUpperCase()
    }
    //导出
    const exports = () => {
      if (gridOption.value.getSelectedRows().length === 0) {
        Message.error('请先勾选')
        return
      } else {
        let idList: any = []
        gridOption.value.getSelectedRows().forEach(function (o: any) {
          idList.push(o['id'])
        })
        //将表头拼接出来
        let head =
            '<th>编号</th><th>品牌名称</th><th>布类类型</th><th>备注</th><th>创建人</th><th>创建时间</th><th>最后修改人</th><th>最后修改时间</th>'
        //拿到当前表格数据与勾选的行做筛选

        let nowRow = table.dataList.filter(function (o) {
          return (
              gridOption.value
                  .getSelectedRows()
                  .map((o: any) => {
                    return o.id
                  })
                  .indexOf(o['id']) !== -1
          )
        })
        let body = ''
        nowRow.forEach(function (o) {
          body += '<tr><td>' + o['brandCode'] + '</td>'
          body += '<td>' + o['brandName'] + '</td>'
          body += '<td>' + o['clothClass'] + '</td>'
          body += '<td>' + o['remark'] + '</td>'
          body += '<td>' + o['createName'] + '</td>'
          body += '<td>' + o['createTime'] + '</td>'
          body += '<td>' + o['updateName'] + '</td>'
          body += '<td>' + o['updateTime'] + '</td>'
          body += '</tr>'
        })
        tableToXlsx(head, '品牌资料', body)
        console.log(table)
      }
    }

    function tableToXlsx(head: any, filename: any, body: any) {
      const uri = 'data:application/vnd.ms-excel;base64,',
          template = `<html>
            <head><meta charset="UTF-8"></head>
            <body><table border="1"><tr>${head}</tr>${body}</table></body>
        </html>`

      const a = document.createElement('a')
      a.href = uri + window.btoa(unescape(encodeURIComponent(template)))
      a.download = filename
      a.click()
      document.removeChild(a)
    }

    //模板下载
    const downloadHandler = () => {
      axios
          .get(baseURL + '/product/Brand/uploadModel', {
            responseType: 'blob',
            headers: {
              token: sessionStorage.getItem('USER-TOKEN-KEY'),
            },
          })
          .then((res) => {
            if (res.status === 200) {
              filedownload(res.data, '品牌资料.xlsx')
            }
          })
    }
    //导入
    const importHandler = () => {
      const inputEle: HTMLInputElement = document.createElement('input')
      inputEle.type = 'file'
      inputEle.id = 'fileUploadExcel'
      inputEle.accept =
          'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel'
      inputEle.addEventListener('change', (e) => {
        const formData = new FormData()
        if (inputEle.files !== null) {
          formData.append('file', inputEle.files[0] || '')
        } else {
          Message.warning('未选择文件！')
          return
        }
        pageData.pageLoading = true
        axios
            .post(baseURL + '/product/Brand/importModelData', formData, {
              headers: {
                'Content-Type': 'multipart/form-data',
                token: sessionStorage.getItem('USER-TOKEN-KEY'),
              },
            })
            .then((result) => {
              if (result.data['code'] === 200) {
                Message.success('导入成功')
              } else {
                Message.error(result.data.message)
              }
            })
            .finally(() => {
              pageData.pageLoading = false
              doRefresh()
            })
      })
      inputEle.click()
    }
    //下拉数据
    const options1 = ref<any>(pageData.customNameList)
    const loading1 = ref(false)
    const handleSearch1 = (value: any) => {
      if (value) {
        const ob = {
          brandName: value,
          deleteState: 0,
        }
        loading.value = true
        selCxAll1(ob)
        options.value = pageData.customNameList
        loading.value = false
      } else {
        options.value = []
      }
    }

    //下拉框查询 客户类型
    function selCxAll1(val: any) {
      post({
        url: 'product/Brand/getFieldValue',
        data: val,
      }).then(({data, code}: any) => {
        if (code === 200) {
          pageData.customNameList = data
        } else {
          Message.error({
            content: '查询失败！',
            duration: 5000,
          })
        }
      })
    }

    //下拉框得到焦点
    const focusSel1 = () => {
      selCxAll1({brandName: '', deleteState: 0})
    }
    //设置权限
    // ['查询', '新增', '删除', '导出', '导入']
    const permissionStore = usePermission()

    if (permissionStore.hasPermisson('wjgylhpbdz.cx')) {
      pageData.btnList.push('查询')
    }
    if (permissionStore.hasPermisson('wjgylhpbdz.xz')) {
      pageData.btnList.push('新增')
    }
    if (permissionStore.hasPermisson('wjgylhpbdz.sc')) {
      pageData.btnList.push('删除')
    }
    // if (permissionStore.hasPermisson('ppzl.dc')) {
    //     pageData.btnList.push("导出")
    // }
    // if (permissionStore.hasPermisson('ppzl.dr')) {
    //     pageData.btnList.push("导入")
    // }
    if (permissionStore.hasPermisson('wjgylhpbdz.xg')) {
      pageData.isEdit = true
    }
    const handleChange = (_data: any) => {
      table.handleSuccess(_data)
    }
    const defaultColDef = {
      sortable: true,
      resizable: true,
      filter: true,
      // flex: 1
    }
    const huiche = () => {
      page.value = 1
      cxbl = pageData.dropDownData
      doRefresh()
    }
    const pagingList1: any = ref(pagingList)
    const localeText1: any = ref(localeText)
    const isbiaodan = ref({
      yuanliaobianhao: '',
      yuanliaobianhaolist: [] as any,
      yuanliaomingcheng: '',
      waijiagongyuanbianhao: '',
      waijiagongyuanliaomingcheng: '',
      pibubianhao: '',
      pibubianhaolist: [] as any,
      pibumingcheng: '',
      waijiagongpibubianhao: '',
      waijiagongpibumingcheng: '',
      waijiagongchang: null as any,
      waijiagongchanglist: [],
      remark: '',
      customName: '',
      title: '',
    })
    const guangzhu = (val: any) => {
      if (val == '原料编号') {
        selectGreycode()
        if (
            isbiaodan.value.yuanliaobianhao != '' ||
            isbiaodan.value.waijiagongyuanbianhao != '' ||
            isbiaodan.value.waijiagongyuanliaomingcheng != ''
        ) {
          jinyong2.value = true
        } else {
          jinyong2.value = false
        }
      } else {
        getpibubianhao()
        if (
            isbiaodan.value.pibubianhao != '' ||
            isbiaodan.value.waijiagongpibubianhao != '' ||
            isbiaodan.value.waijiagongpibumingcheng != ''
        ) {
          jinyong1.value = true
        } else {
          jinyong1.value = false
        }
      }
    }
    const selectGreycode = () => {
      post({
        url: 'product/Rawmaterial/getPageInfo',
        data: {
          page: 1,
          size: 30,
          deleteState: '0',
          auditState: '',
          rawmaterialCode: '',
          materialsName: '',
          grayFabricName: '',
          model: '',
          materialsCategory: '',
          accountType: 1,
        },
      })
          .then(({data, code}: any) => {
            if (code === 200) {
              isbiaodan.value.yuanliaobianhaolist = data.list
            }
          })
          .catch(console.log)
          .finally(() => {
            pageData.pageLoading = false
          })
    }
    const getpibubianhao = () => {
      isbiaodan.value.pibubianhaolist = []
      post({
        url: 'product/pdGreyInformation/selectpdGreyInformationPage',
        data: {
          page: 1,
          size: 30,
          deleteState: 0,
          greyCode: '',
          grayFabricName: '',
          productKind: '',
          auditState: 1,
        },
      })
          .then(({data, code}: any) => {
            if (code === 200) {
              isbiaodan.value.pibubianhaolist = data.list
            }
          })
          .catch(console.log)
          .finally(() => {
            pageData.pageLoading = false
          })
    }
    const huoquzhi = (value: any) => {
      isbiaodan.value.yuanliaomingcheng = value.materialsName
    }
    const huoquzhi2 = (value: any) => {
      isbiaodan.value.pibumingcheng = value.grayFabricName
    }
    const id = ref(null)
    const jinyong1 = ref(false)
    const jinyong2 = ref(false)
    const huoquzhi3 = () => {
      post({
        url: 'org/baCompany/getTreeCompanyByUser',
        data: {},
      }).then(({code, data}) => {
        if (code === 200) {
          isbiaodan.value.waijiagongchanglist = data
        }
      })
    }
    const isyuanliao = () => {
      isbiaodan.value.yuanliaomingcheng = ''
      if (
          isbiaodan.value.yuanliaobianhao != '' ||
          isbiaodan.value.waijiagongyuanbianhao != '' ||
          isbiaodan.value.waijiagongyuanliaomingcheng != ''
      ) {
        jinyong2.value = true
      } else {
        jinyong2.value = false
      }
    }
    const ispibu = () => {
      isbiaodan.value.pibumingcheng = ''
      if (
          isbiaodan.value.pibubianhao != '' ||
          isbiaodan.value.waijiagongpibubianhao != '' ||
          isbiaodan.value.waijiagongpibumingcheng != ''
      ) {
        jinyong1.value = true
      } else {
        jinyong1.value = false
      }
    }

    const sousuoyuanliaobianhao = (value: any) => {
      isbiaodan.value.yuanliaobianhaolist = []
      post({
        url: 'product/Rawmaterial/getPageInfo',
        data: {
          page: 1,
          size: 30,
          deleteState: '0',
          auditState: '',
          rawmaterialCode: value,
          materialsName: '',
          grayFabricName: '',
          model: '',
          materialsCategory: '',
          accountType: 1,
        },
      })
          .then(({data, code}: any) => {
            if (code === 200) {
              isbiaodan.value.yuanliaobianhaolist = data.list
            }
            console.log(isbiaodan.value.yuanliaobianhaolist)
          })
          .catch(console.log)
          .finally(() => {
            pageData.pageLoading = false
          })
    }
    const sousuopibubianhao = (value: any) => {
      console.log(value)
      isbiaodan.value.pibubianhaolist = []
      post({
        url: 'product/pdGreyInformation/selectpdGreyInformationPage',
        data: {
          page: 1,
          size: 30,
          deleteState: 0,
          greyCode: value,
          grayFabricName: '',
          productKind: '',
          auditState: 1,
        },
      })
          .then(({data, code}: any) => {
            if (code === 200) {
              isbiaodan.value.pibubianhaolist = data.list
            }
          })
          .catch(console.log)
          .finally(() => {
            pageData.pageLoading = false
          })
    }
    const casOb = ref()
    //公司改变
    const cascaderChange = () => {
      //拿到选中的这个节点数组
      setTimeout(function () {
        if (casOb.value.selectViewValue.length != 0) {
          console.log(casOb.value.selectViewValue)

          isbiaodan.value.title = slicing(casOb.value.selectViewValue[0]['label'])
        }
      }, 100)
    }
    return {
      colState,
      casOb,
      cascaderChange,
      sousuoyuanliaobianhao,
      sousuopibubianhao,
      isyuanliao,
      ispibu,
      huoquzhi3,
      jinyong1,
      jinyong2,
      id,
      huoquzhi2,
      getpibubianhao,
      huoquzhi,
      guangzhu,
      isbiaodan,
      pagingList1,
      huiche,
      localeText1,
      defaultColDef,
      tc,
      total,
      PageSize,
      change1,
      page,
      size,
      editHandler,
      deleteHandler,
      sideOk,
      formRef,
      dataForm,
      addHandler,
      selectedRowKeys,
      pagination,
      tableColumns,
      table,
      rowKey,
      pageData,
      queryData,
      selectHandler,
      isChiese,
      inputBlur,
      exports,
      options,
      loading,
      handleSearch,
      focusSel,
      downloadHandler,
      importHandler,
      options1,
      loading1,
      handleSearch1,
      focusSel1,
      headerShow,
      handleChange,
      gridReady,
      table1Ref,
      configTable1
    }
  },
  components: {Toolbar, PageTabelLayout, },
}
</script>
